package com.fhao.friend.controller.exam;

import com.fhao.common.core.controller.BaseController;
import com.fhao.common.core.domain.R;
import com.fhao.common.core.domain.TableDataInfo;
import com.fhao.friend.domain.exam.dto.ExamQueryDTO;
import com.fhao.friend.domain.exam.dto.ExamRankDTO;
import com.fhao.friend.domain.exam.vo.ExamRankVO;
import com.fhao.friend.domain.exam.vo.ExamVO;
import com.fhao.friend.service.exam.IExamService;
import com.fhao.friend.service.user.IUserService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {

    @Autowired
    private IExamService examService;

    @GetMapping("/semiLogin/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
        List<ExamVO> examVOList = examService.list(examQueryDTO);
        return getTableDataInfo(examVOList);
    }

    @GetMapping("/semiLogin/redis/list")
    public TableDataInfo redisList(ExamQueryDTO examQueryDTO) {
        return examService.redisList(examQueryDTO);
    }

    //查询竞赛排名
    @GetMapping("/rank/list")
    public TableDataInfo rankList(ExamRankDTO examRankDTO) {
        return examService.rankList(examRankDTO);
    }

    /**
     * 返回竞赛当中的首道题目
     * @param examId 竞赛id
     * @return
     */
    @GetMapping("/getFirstQuestion")
    public R<String> getFirstQuestion(Long examId) {
        //代码逻辑: 获取竞赛题目的顺序列表 排在第一个的题目 返回给前端.
        //先去redis中找, 找不到再去数据库找   结构: list  key: e:q:l:examId  value : questionId
        return R.ok(examService.getFirstQuestion(examId));
    }

    @GetMapping("/preQuestion")
    public R<String> preQuestion(Long examId,Long questionId) {
        return R.ok(examService.preQuestion(examId,questionId));
    }

    @GetMapping("/nextQuestion")
    public R<String> nextQuestion(Long examId,Long questionId) {
        return R.ok(examService.nextQuestion(examId,questionId));
    }

}
